<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: add.phtml 4182 2010-08-01 16:27:10Z huuphuoc $
 * @since		2.0.0
 */
?>
<?php 
$this->headTitle($this->translator('zone_add_page_title'));
$this->headLink()->appendStylesheet($this->APP_STATIC_SERVER. '/skins/admin/default/css/form.css');
$this->headScript()->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate.min.js');
?>
<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/article.png'; ?>" alt=""/>
    <span><?php echo $this->translate('zone_add_breadcrumb') ?></span>
</div>
<?php
$massage = $this->flashMessenger();
if ($massage) {
    ?>
    <div id="message"><?php echo $massage; ?></div>
<?php } ?>


<form method="post" action="<?php echo $this->url(array(), 'ad_zone_add'); ?>" id="addZoneForm">
    <div class="grid_12 t_a_bottom"><?php echo $this->translator('zone_add_guide'); ?></div>
    <div class="row">
            <label><?php echo $this->translator('zone_name'); ?>:</label>
            <input type="text" id="name" name="name" style="width: 200px" />
    </div>		
    <div class="row">
            <label><?php echo $this->translator('zone_description'); ?>:</label>
            <textarea name="description" id="description" style="width: 400px; height: 100px"></textarea>
    </div>
    <div class="row">
            <label><?php echo $this->translator('zone_width'); ?>:</label>
            <input type="text" id="width" name="width" style="width: 50px" />
    </div>	
    <div class="row">
            <label><?php echo $this->translator('zone_height'); ?>:</label>
            <input type="text" id="height" name="height" style="width: 50px" />
    </div>
	
    <div class="row">
            <label>&nbsp;</label>
            <button type="submit" class="button"><span><?php echo $this->translator('zone_add_save_button'); ?></span></button>
    </div>
</form>

<script type="text/javascript">
$(document).ready(function() {
	/**
	 * Validate form
	 */
	$.validator.addMethod('specialCharacter', function(value) {
		value = value.replace(/^\s+|\s+$/g, '');
		var regex = new RegExp(/^[a-zA-Z0-9\-]+$/);
		return value == '' || value.match(regex);
	});
	
	$('#addZoneForm').validate({
            rules: {
                name: {
                    required: true,
                    specialCharacter: true,
                    remote: '<?php echo $this->url(array(), 'ad_zone_check'); ?>'
                },
                width: {
                    required: true,
                    number: true
                },
                height: {
                    required: true,
                    number: true
                }
	    },
	    messages: {
	    	name: {
                    required: "<?php echo $this->translator('zone_name_required'); ?>",
                    //specialCharacter: "<?php echo $this->translator('zone_name_invalid'); ?>",
                    remote: "<?php echo $this->translator('zone_name_exist'); ?>"
                },
                width: {
                    required: "<?php echo $this->translator('zone_width_required'); ?>",
                    number: "<?php echo $this->translator('zone_number_required'); ?>"
                },
                height: { 
                    required: "<?php echo $this->translator('zone_height_required'); ?>",
                    number: "<?php echo $this->translator('zone_number_required'); ?>"
	    	}
            }   
	});
});
</script>
